<?php
include_once('Dao.php');
include_once(realpath(dirname(__FILE__)).'/../user.php');

class RegistrationDao extends Dao {
    private $_UNUSED_VALUE_ = 0;

    public function __construct() {
        parent::__construct();
    }

    /* inserts a registration (input = team id, term)
     * returns: on success: 1
     *          on error: 0
     */
    public function insert($team_id, $period_term) {
        $sql = <<<SQL
INSERT INTO registration VALUES
($team_id
,$period_term
,0)
SQL;
        $result = mysql_query($sql, $this->m_cx);
	if( !$result ) {
	    echo "insert: sql query error".mysql_error();
	    return 0;
	}
        return $result;
    }

    /* removes a registration (input = team id, term)
     * returns: on success: 1
     *          on error: 0
     */
     /*
    public function remove($team_id, $period_term) {
        $tid = $registration->team->getId();
	$pid = $registration->period->getId();
        $sql = <<<SQL
DELETE FROM registration VALUES
('$tid'
,'$pid'
,$_UNUSED_VALUE_)
SQL;
         $result = mysql_query($sql, $this->m_cx);
	 return $result;
    }
    */

    /* updates a registration (input = Registration class)
     * returns: on success: 1
     *          on error: 0
     */
    /*
    public function update($registration) {
         $tid = $registration->team->getId();
	 $pid = $registration->period->getId();

         $sql = <<<SQL
UPDATE registration SET
 tid = $tid
,pid = $pid
,$_UNUSED_VALUE_
SQL;
        $result = mysql_query($sql, $this->m_cx);
        return $result;
    }
    */

    /* look-up the list of teams for a particular term
     * returns: on success: an array of team IDs
     *          on error: -1
     */
     /*
    public function lookupByTerm($term_id) {
         $sql = <<<SQL
SELECT r.tid
FROM registration r
WHERE r.term = $term_id
SQL;
        $result = mysql_query($sql, $this->m_cx);
	if( !$result) die( mysql_error() );

	while( $r = mysql_fetch_assoc($result) ) {
	    $ret[] = $r['tid'];
	}
	return ret;
    }
    */

    /* whether a team is registered in a particular term 
     * returns: boolean whether team is registered
     */
     /*
    public lookupIsTeamRegistered($team_id, $term_id) {
         $sql = <<<SQL
SELECT r.tid
FROM registration r
WHERE r.term = $term_id AND r.tid = $team_id
SQL;
        $result = mysql_query($sql, $this->m_cx);
	if( !$result) die( mysql_error() );
	return mysql_num_rows > 0;
    }
    */

    /* find all registered teams for a term
     * returns: array of team id on success, 0 on fail.
     */
     /*
    public lookupRegistrations($term_id) {
         $sql = <<<SQL
SELECT tid
FROM registration 
WHERE term = $term_id
SQL;
        $result = mysql_query($sql, $this->m_cx);
	if( !$result) {
	    echo "lookupRegistrations: Look up of term failed: ".mysql_error();
	}
	$ret = array();
        while( $r = mysql_fetch_assoc($result) ) {
	    array_push($ret, $r['tid']);
	}
	return $ret;
    }
    */

}//class 
?>
